import os
import random

class Scoring:
    name = "LMN"
    wins = []
    currentsco = 0
    difficultybonus = 0
    def __init__(self):
        #opens save file if it exists, makes it if it doesn't
        if os.path.isfile('./testscore0.sav'):
            print('OPENING OLD SAV')
            sav = open('testscore0.sav','r')
            intlist = sav.readlines()
            for line in intlist:
                x = line.strip('\n').split(':')
                
                self.wins.append([x[0],int(float(x[1]))])

            sav.close()
        else:
            print('WRITING NEW FILE')
            sav = open('testscore0.sav','w')
            for pair in self.wins:
                #for cool in pair:
                sav.write(pair[0] + ":" + str(pair[1]) + "\n")
                    #for item in pair:
                        #sav.write(item)
                #sav.write(str(self.wins))
            sav.close()
    def setdifficultybonus(self):
        self.difficultybonus = input("bonus: ")
    def addscore(self):
        #adds to the score and writes it
        self.currentsco += 1
    def writescore(self):
        print('WRITING TO FILE')
        sav = open('testscore0.sav','w')
        for pair in self.wins:
            #for cool in pair:
            sav.write(pair[0] + ":" + str(pair[1]) + "\n")
            #sav.write(str(pair))
        #sav.write(str(self.wins))
        sav.close()
        return self.wins
    def viewscore(self):
        #prints the current score
            
        for score in self.wins:
            print(score)
    def losereset(self):
        #resets the score on loss and writes it
        print("The score is reset!")
        self.wins = 0
        print('WRITING NEW FILE')
        sav = open('testscore0.sav','w')
        for score in wins:
            sav.write(str(self.wins))
        sav.close()
    def testingscore(self):
        self.wins = [["LMN", 99],["LMM",44],["CAP",22]]

    
hiscore = Scoring()
#hiscore.testingscore()
hiscore.viewscore()
print(hiscore.wins)
#hiscore.writescore()
